package org.info.controller;

import java.util.Date;
import java.util.List;

import org.info.dto.JsgxMobileDataResult;
import org.info.dto.QueryExcution;
import org.info.enums.JsgxMobileDataStateEnum;
import org.info.model.JsgxMobileData;
import org.info.service.JsgxMobileDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
//@RequestMapping("/jsgx")
public class JsgxMobileDataController {

	@Autowired
	private JsgxMobileDataService jsgxMobileDataService;
	
	@RequestMapping(value="/{saleAttr}/{typeId}/data", method = RequestMethod.GET)
	public String findOne(
			@PathVariable("saleAttr") String saleAttr,
			@PathVariable("typeId") String typeId,
			Model model) {
		JsgxMobileData data = jsgxMobileDataService.getById(saleAttr, typeId);
		Date updateTime = data.getGxDate();
		model.addAttribute("updateTime", updateTime);
		return "list";
	}

	@RequestMapping(value="/{saleAttr}/{typeId}/getData", method = RequestMethod.GET)
	@ResponseBody
	public JsgxMobileDataResult<QueryExcution> getData(
			@PathVariable("saleAttr") String saleAttr,
			@PathVariable("typeId") String typeId,
			Model model) {
		
		try {
			QueryExcution queryExcution = jsgxMobileDataService.getList(saleAttr, typeId);
			return new JsgxMobileDataResult<QueryExcution>(true, "success" ,queryExcution);
		} catch (Exception e) {
			QueryExcution queryExcution = new QueryExcution(typeId, saleAttr, JsgxMobileDataStateEnum.INNER_ERROR);
			return new JsgxMobileDataResult<QueryExcution>(false, "failure" ,queryExcution);
		}
	}
}
